package io.github.rascaler.dcenter.platforms.binance;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.github.rascaler.dcenter.platforms.Parser;
import io.github.rascaler.dcenter.pojo.Candlestick;
import io.github.rascaler.dcenter.pojo.Instrument;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName BinanceInstrumentParser
 * @Description TODO
 * @Author wurenqing
 * @Date 2023-12-08 10:45
 */
@Component("binanceCandlestickParser")
public class BinanceCandlestickParser implements Parser {
    @Override
    public List<Candlestick> parse(Object origin) {
        if (null == origin) {
            return null;
        }
        List<JSONArray> list = JSON.parseArray(origin.toString(), JSONArray.class);
        List<Candlestick> result = list.stream().map(e -> {
            Candlestick candlestick = new Candlestick();
            candlestick.setBarDate(e.getLong(0));
            candlestick.setOpen(e.getBigDecimal(1));
            candlestick.setHigh(e.getBigDecimal(2));
            candlestick.setLow(e.getBigDecimal(3));
            candlestick.setClose(e.getBigDecimal(4));
            candlestick.setVolume(e.getBigDecimal(5));
            candlestick.setAmount(new BigDecimal(0));
            return candlestick;
        }).collect(Collectors.toList());
        return result;
    }
}
